<?php
namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\User as userModel;

class Register extends Controller

{
    public function register()
    {
        return view('register');
    }
    public function register_ok(Request $request)
    {
          $this->validate($request,
              [
                  'uname'=>'required',
                  'utel'=>'required|size:11',
                  'upassword'=>'required',
                  'repassword'=>'required|same:upassword',
              ],
              [
                  'uname.required'=>'用户名不能为空',
                  'utel.required'=>'电话不能为空',
                  'utel.size'=>'电话格式不正确',
                  'upassword.required'=>'密码不能为空',
                  'repassword.required'=>'确认密码不能为空',
                  'repassword.same'=>'两次密码输入不一致',
              ]
          );
          $post=$request->post();
          $user = new userModel($post);
          $user->getUpwdAttribute($post['upassword']);
          $user->getRepwdAttribute($post['repassword']);
          $user->save();
          return ['code'=>1,'name'=>'注册成功','url'=>'/login'];
    }
}
